<?php
/*
Plugin Name: WP Paypal Shortcodes
Plugin URI: http://www.webtux.info/wordpress-plugins/
Description: Add paypal button with shortcodes.
Version: 0.1
Author: Michael DUMONTET
Author URI: http://www.webtux.info/wordpress-plugins/wp-paypal-shortcodes

Copyright 2011  Michael DUMONTET  (email : contact@webtux.info)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as 
published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

// SOURCE : aide pour realiser un plugin wordpress http://codex.wordpress.org/Writing_a_Plugin

// Gestion lang (dossier lang dans le plugin, contenant les .mo)
load_plugin_textdomain("wp-paypal-shortcodes", false, dirname( plugin_basename( __FILE__ ) ) . '/lang');



// Config plugin :
define("PAYPAL_EMAIL_SELLER",			"seller_1245921548_biz@uwl-communication.com");	// seller email
define("PAYPAL_PAGE_RETURN",			get_bloginfo('template_url')."/paypal_return.php");	// return page (after buy)
define("PAYPAL_PAGE_CANCEL",			get_bloginfo('template_url')."/paypal_cancel.php");
define("PAYPAL_PAGE_NOTIFY_URL",		get_bloginfo('template_url')."/paypal_notify_url.php");



// Shortcodes : add button paypal
function getPaypalBtn( $atts='' ){
	// recup valeur autorisée par le shortcode
	extract( shortcode_atts(array(
		'production'	=> 'false',						// true : production, false : test phase (=sandbox) 
		'amount'		=> 44,							// montant du produit
		'currency_code'	=> 'EUR',						// devise
		'shipping'		=> '0.00',						// tarif transport
		'tax'			=> '0.00',						// tarif tax
		'return'		=> PAYPAL_PAGE_RETURN,			// page de retour, suite paiement
		'cancel_return'	=> PAYPAL_PAGE_CANCEL,			// page de retour, suite annulation du paiement
		'notify_url'	=> PAYPAL_PAGE_NOTIFY_URL,		// suite validation du paiement (IPN)
		'on0'			=> '',							// option 0 : key
		'os0'			=> '',							// option 0 : value
		'on1'			=> '',							// option 1 : key
		'os1'			=> '',							// option 1 : value
		'on2'			=> '',							// option 2 : key
		'os2'			=> '',							// option 2 : value
		'business'		=> PAYPAL_EMAIL_SELLER,			// email du compte paypal du vendeur (nous)
		'item_name'		=> '',							// nom du produit à vendre
		'no_note'		=> '0',							// note dispo pour le client lors de l'achat (0: note dispo, 1: pas de note)
		'lc'			=> 'FR',						// localisation (FR)
		'bn'			=> 'PP-BuyNowBF',				// bouton
		'custom'		=> ''							// champ facultatif (on y inscrit se qu'on veut)
	), $atts ));
	/*$id = (int)$id;
	if( $id == 0 ){
		return '';
	}//fin if*/
	
	// State : production or Test
	if( $production == "false" ){	$urlPaypal = "https://www.sandbox.paypal.com/cgi-bin/webscr"; }
	else{							$urlPaypal = "https://www.paypal.com/cgi-bin/webscr"; }

	// DEBUT - bouton paypal
	/**
	 * SOURCE :
	 * http://www.lafermeduweb.net/billet/tutorial-integrer-paypal-a-son-site-web-en-php-partie-1-275.html
	 * http://www.lafermeduweb.net/billet/tutorial-integrer-paypal-a-son-site-web-en-php-partie-2-276.html
	 */  
	?>
	<form action="<?php echo $urlPaypal; ?>" method="post">
		<input name="amount" type='hidden' value="<?php echo $amount; ?>" />
		<input name="currency_code" type="hidden" value="<?php echo $currency_code; ?>" />
		<input name="shipping" type="hidden" value="<?php echo $shipping; ?>" />
		<input name="tax" type="hidden" value="<?php echo $tax; ?>" />
				
		<?php // adresse de retour, après le paiement ?>
		<input name="return" type="hidden" value="<?php echo $return; ?>" />
		<?php // adresse d'annulation du paiement ?>
		<input name="cancel_return" type="hidden" value="<?php echo $cancel_return; ?>" />
		<?php // adresse de notification d'achat réalisé (IPN) ?>
		<input name="notify_url" type="hidden" value="<?php echo $notify_url; ?>" />
				
		<?php // OPTION 0 : ?>
		<input name="on0" type="hidden" value="<?php echo $on0;?>" />
		<input name="os0" type="hidden" value="<?php echo $os0; ?>" />
		<?php // OPTION 1 : ?>
		<input name="on1" type="hidden" value="<?php echo $on1;?>" />
		<input name="os1" type="hidden" value="<?php echo $os1; ?>" />
		<?php // OPTION 2 : ?>
		<input name="on2" type="hidden" value="<?php echo $on2;?>" />
		<input name="os2" type="hidden" value="<?php echo $os2; ?>" />
		<?php // OPTION 3 : ?>
		<input name="on3" type="hidden" value="<?php echo $on3;?>" />
		<input name="os3" type="hidden" value="<?php echo $os3; ?>" />
		<?php // OPTION 4 : ?>
		<input name="on4" type="hidden" value="<?php echo $on4;?>" />
		<input name="os4" type="hidden" value="<?php echo $os4; ?>" />
				
		<!-- <input type="hidden" value="billing" name="LandingPage" /> -->
				
		<input name="cmd" type="hidden" value="_xclick" />
		<input name="business" type="hidden" value="<?php echo $business; ?>" />
		<input name="item_name" type="hidden" value="<?php echo $item_name; ?>" />
		<input name="no_note" type="hidden" value="<?php echo no_note; ?>" />	<!-- supprimer les notes de l'acte d'achat -->
		<input name="lc" type="hidden" value="<?php echo $lc; ?>" />
		<input name="bn" type="hidden" value="<?php echo $bn; ?>" />	<!-- parametre pour le bouton -->
		<input name="custom" type="hidden" value="<?php echo $custom; ?>" />
		<input alt="Effectuez vos paiements via PayPal : une solution rapide, gratuite et sécurisée" name="submit" src="https://www.paypal.com/fr_FR/FR/i/btn/btn_buynow_LG.gif" type="image" /><img src="https://www.paypal.com/fr_FR/i/scr/pixel.gif" border="0" alt="" width="1" height="1" />
	</form>
	<?php _e("Buy with PayPal", "wp-paypal-shortcodes"); ?>
	<?php // FIN - bouton paypal ?>

<?php 				
}//fin function
add_shortcode('paypalBtn', 'getPaypalBtn');